package com.sj.purchase.modules.cost.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.*;
import java.util.Date;

/**
 * @author MaJinGe 2017/11/06
 */
@Entity
@Table(name = "l_success_task")
public class SucTask extends AbstractPersistable<Long> {

    @Enumerated(EnumType.STRING)
    private TaskType taskType;

    @Temporal(TemporalType.DATE)
    private Date taskDay;

    public SucTask() {
    }

    public SucTask(TaskType taskType, Date taskDay) {
        this.taskType = taskType;
        this.taskDay = taskDay;
    }

    public TaskType getTaskType() {
        return taskType;
    }

    public void setTaskType(TaskType taskType) {
        this.taskType = taskType;
    }

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    public Date getTaskDay() {
        return taskDay;
    }

    public void setTaskDay(Date taskDay) {
        this.taskDay = taskDay;
    }

    public enum TaskType {
        SYNC_STOCK("同步库存"),      //库存
        SYNC_ADJUSTMENT("同步调整单"),//调整单
        SYNC_IN_ORDER("同步入库"), //入库
        SYNC_OUT_ORDER("同步出库"), //出库
        SYNC_INVENTORY("同步库存明细"),//库存明细
        COMPUTE_COST_PRICE("计算平均价", false),
        COMPUTE_STOCK_CONTRAST("计算库存差异", false);


        private String name;
        private Boolean isSync;

        TaskType(String name) {
            this(name, true);
        }

        TaskType(String name, Boolean isSync) {
            this.name = name;
            this.isSync = isSync;
        }

        @JsonValue
        public String getName() {
            return name;
        }

        public Boolean getIsSync() {
            return isSync;
        }
    }
}
